#define _GNU_SOURCE     // 声明可以使用系统库的扩展语法 gettid()
#include "pthread.h"
#include "stdio.h"
#include "unistd.h"

//第一个线程的执行函数
void * thread1_run(void *arg)
{
    printf("thread1_run 线程1的线程ID = %d\n", gettid());
    return NULL;
}

//第二个线程的执行函数
void * thread2_run(void *arg)
{
    printf("thread2_run 线程2的线程ID = %d\n", gettid());
    return NULL;
}

int main(int argc, char const *argv[])
{
    printf("main 主函数的线程ID = %d\n", gettid());

    // 创建两个分线程
    pthread_t thread1;      // 类型是 unsigned long
    pthread_t thread2;      // 类型是 unsigned long
    pthread_create(&thread1, NULL, thread1_run, NULL);
    pthread_create(&thread2, NULL, thread2_run, NULL);

    printf("main 主函数的线程继续执行,线程ID = %d\n", gettid());

    // 等待2个分线程执行完毕
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    printf("main 主函数即将结束执行,线程ID = %d\n", gettid());

    return 0;
}